Programming Bitcoin by Jimmy Song

Programming Bitcoin by Jimmy Song

Author:Jimmy Song [Jimmy Song]
Language: eng
Format: epub, azw3, pdf
Publisher: O'Reilly Media, Inc.
Published: 2019-03-24T22:00:00+00:00


>>> from ecc import FieldElement, Point >>> a = FieldElement(num=0, prime=223) >>> b = FieldElement(num=7, prime=223) >>> x = FieldElement(num=192, prime=223) >>> y = FieldElement(num=105, prime=223) >>> p1 = Point(x, y, a, b) >>> print(p1) Point(192, 105)_223

When initializing Point, we will run through this part of the code:

class Point: zero = 0 def __init__(self, x, y, a, b): self.a = a self.b = b self.x = x self.y = y if self.x is None and self.y is None: return if self.y**2 != self.x**3 + self.a*self.x + self.b: raise ValueError('Point ({},{}) is not on the curve'.format(x,y))

The addition (+), multiplication (), exponentiation (*) and equality (!=) here will end up utilizing the __add__, __mul__, __pow__ and __ne__ methods from FiniteField respectively and not the integer equivalents. As we will see, being able to do the same equation but with different definitions for the basic arithemtic operators is what will allow us to construct an Elliptic Curve Cryptography library.

We’ve already coded the two classes that we need to implement Elliptic Curve points over a Finite Field. However, to check our work, it will be useful to create a test suite. We will do this using the results of the previous exercise.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.